import Vue from 'vue'
import VueRouter from 'vue-router'

// import Home from '../views/Home.vue'
// import Order from '../views/Order.vue'
// import Search from '../views/Search.vue'
// import Profile from '../views/Profile.vue'
// 返回路由组件的函数，只有执行该函数才会加载路由组件，这个函数在请求对应的路由路径时才会执行
const Home = () => import('../views/Home.vue')
const Order = () => import('../views/Order.vue')
const Search = () => import('../views/Search.vue')
const Profile = () => import('../views/Profile.vue')

import Login from '../views/Login.vue'
import Shop from '../views/shop/Shop.vue'
import ShopGoods from '../views/shop/shopgoods/ShopGoods.vue'
import ShopInfo from '../views/shop/shopgoods/ShopInfo.vue'
import ShopRating from '../views/shop/shopgoods/ShopRating.vue'

Vue.use(VueRouter)

  const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta:{
      showFooter: true,
      isLogin: true
    }
  },
  {
    path: '/order',
    name: 'Order',
    component: Order,
    meta:{
      showFooter: true,
      isLogin: false
    }
  },
  {
    path: '/search',
    name: 'Search',
    component: Search,
    meta:{
      showFooter:true
    }
  },
  {
    path: '/profile',
    name: 'Profile',
    component: Profile,
    meta:{
      showFooter: true,
      isLogin: false
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/shop',
    name: 'Shop',
    component: Shop,
    children:[
      {
        path: '/shop/goods',
        name: 'ShopGoods',
        component: ShopGoods
      },
      {
        path: '/shop/info',
        name: 'ShopInfo',
        component: ShopInfo
      },
      {
        path: '/shop/rating',
        name: 'ShopRating',
        component: ShopRating
      },
      {
        path: '',
        redirect:'/shop/goods'
      },
    ]
  }
]
// 重写路由的push方法
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}

const router = new VueRouter({
  routes
})

export default router
